<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>用户管理</title>
    <span th:replace="common/link"></span>
    <script>
        $(function () {
            $("#editForm").submit(function () {
                $(".selectedOptions option").prop("selected", true);
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <div th:replace="common/navbar::navBar"></div>
    <!--菜单回显-->
    <div th:replace="common/menu::menuBar"></div>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>用户编辑</h1>
        </section>
       <section class="content">
            <div class="box">
                <form class="form-horizontal" action="/user/saveOrUpdate" method="post" id="editForm">
                    <input type="hidden" th:value="${user!=null}?${user.id}" name="id"/>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-2 control-label">用户名：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="name" name="username"
                                   placeholder="请输入用户名" th:value="${user!=null}?${user.username}">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="pwd" class="col-sm-2 control-label">密&nbsp;&nbsp;&nbsp;码：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="pwd" name="password"
                                   placeholder="请输入密码"  th:value="${user!=null}?${user.password}">
                        </div>
                    </div>
                    <div class="form-group " id="role">
                        <label for="role" class="col-sm-2 control-label">分配角色：</label><br/>
                        <div class="row" style="margin-top: 10px">
                            <div class="col-sm-2 col-sm-offset-2">
                                <strong>未选的:</strong>
                                <select multiple class="form-control unSelectedOptions" size="15" th:if="${unSelectedRoles != null}">
                                    <option  th:text="${role.name}" th:value="${role.id}" th:each="role:${unSelectedRoles}"></option>
                                </select>
                                <select multiple class="form-control unSelectedOptions" size="15" th:unless="${unSelectedRoles != null}">

                                </select>
                            </div>

                            <div class="col-sm-1" style="margin-top: 60px;" align="center">
                                <div>

                                    <a type="button" class="btn btn-primary  " style="margin-top: 10px" title="右移动"
                                       onclick="moveSelected('unSelectedOptions', 'selectedOptions')">
                                        <span class="glyphicon glyphicon-menu-right"></span>
                                    </a>
                                </div>
                                <div>
                                    <a type="button" class="btn btn-primary " style="margin-top: 10px" title="左移动"
                                       onclick="moveSelected('selectedOptions', 'unSelectedOptions')">
                                        <span class="glyphicon glyphicon-menu-left"></span>
                                    </a>
                                </div>
                                <div>
                                    <a type="button" class="btn btn-primary " style="margin-top: 10px" title="全右移动"
                                       onclick="moveAll('unSelectedOptions', 'selectedOptions')">
                                        <span class="glyphicon glyphicon-forward"></span>
                                    </a>
                                </div>
                                <div>
                                    <a type="button" class="btn btn-primary " style="margin-top: 10px" title="全左移动"
                                       onclick="moveAll('selectedOptions', 'unSelectedOptions')">
                                        <span class="glyphicon glyphicon-backward"></span>
                                    </a>
                                </div>
                            </div>

                            <div class="col-sm-2">
                                <strong>已选:</strong>
                                <select multiple class="form-control selectedOptions" size="15" name="roleIds" th:if="${user != null && user.roleList != null }">
                                    <option   th:value="${role.id}" th:text="${role.name}"  th:each="role:${user.roleList}"></option>
                                </select>
                                <select multiple class="form-control selectedOptions" size="15" name="roleIds" th:unless="${user != null && user.roleList != null }">

                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6">
                            <button id="submitBtn" type="submit" class="btn btn-primary">保存</button>
                            <button type="reset" class="btn btn-danger">重置</button>
                        </div>
                    </div>

                </form>

            </div>

        </section>
    </div>
    <div th:replace="common/footer::footerPage"></div>
</div>

</body>
</html>